package com.caojm.mptools.client.commands;

import com.caojm.mptools.client.MptoolsClient;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import com.caojm.mptools.client.utils.DatabaseHelper;
import net.minecraft.text.Text;

public class UnbindCommand {
    public static void register(){
        CommandManager.literal("mp")
                .then(CommandManager.literal("unbind"))
                .executes(context -> {
                    ServerCommandSource source = context.getSource();  // 获取命令来源（玩家）
                    String playerName = source.getName();  // 获取玩家名称

                    boolean success = DatabaseHelper.unbindAccount(playerName);

                    if (success) {
                        // 输出解绑成功的反馈
                        source.sendFeedback(() -> Text.of("账号解绑成功！"), false);
                        MptoolsClient.LOGGER.info("玩家 " + playerName + " 解绑了账号");
                    } else {
                        // 如果解绑失败，返回失败信息
                        source.sendFeedback(() -> Text.of("账号解绑失败，请稍后再试。"), false);
                        MptoolsClient.LOGGER.error("玩家 " + playerName + " 解绑账号失败");
                    }
                    return 1;
                }).build();
    }
}
